<template>
	<el-table
		ref="multipleTable"
		:data="tableData"
		:default-sort="{ prop: 'name', order: 'descending' }"
	     :row-style="{ height: '37px' }"
				:cell-style="{ padding: '0' }"
		size="medium"
		style="width: 100%"
	>
		<el-table-column align="center" label="序号" type="index" width="60"> </el-table-column>
		<el-table-column align="center" property="no" label="物品编号" width="180px" show-overflow-tooltip />
		<el-table-column align="center" property="name" label="物品名称" show-overflow-tooltip />
		<el-table-column align="center" property="source" label="规格型号" show-overflow-tooltip />
		<el-table-column align="center" property="extractionParts" label="产地" show-overflow-tooltip />
		<el-table-column align="center" property="evidencePerson" label="颜色/获取时间" width="150px" show-overflow-tooltip>
			<template #default="scope">{{ `${scope.row.extractionPersonName}/${dateFormat(scope.row.extractionDateTime)}` }}</template>
		</el-table-column>
		<el-table-column align="center" property="extractMethod" label="获取方式" show-overflow-tooltip />
		<el-table-column v-if="!showOperation"  align="center" width="240px" property="evidencePerson" sortable :label="outTypeTitle + '数量/总数'" show-overflow-tooltip>
			<template #default="scope">{{ `${scope.row.quantity}/${scope.row.quantity}` }}</template>
		</el-table-column>
		<el-table-column  align="center" width="240px" property="evidencePerson" sortable :label="outTypeTitle + '数量/总数'" show-overflow-tooltip v-else>
			<template #default="scope">
				<el-input-number readonly v-model="scope.row.quantity" :min="1" :max="scope.row.quantity" style="width: 120px" /> /{{ scope.row.quantity }}
			</template>
		</el-table-column>
		<el-table-column align="center" property="location" sortable label="位置" show-overflow-tooltip v-if="outType != 6" />
		<el-table-column align="center" label="操作"  v-if="showOperation">
			<template #default="scope">
				<el-button v-if="showOperation" type="primary" plain size="mini" @click="onEditEvidenceInfo(scope.row)">移除</el-button>
			</template>
		</el-table-column>

		<el-table-column align="center" label="操作"  v-if="!showOperation && outType ==6">
			<template #default="scope">
				<el-button  v-if="!showOperation && outType ==6 "  type="success" size="mini" plain   @click="onPrintEviInfo(scope.row)" >打印标签</el-button>
			</template>
		</el-table-column>
	</el-table>
	<EviPrint ref="eviPrintRef"  />
</template>
<script lang="ts">
import { toRefs, reactive,ref } from 'vue';
import { dateFormat } from '/@/common/index';
import { GetCaseBorrowEvdences } from '/@/api/evidence/index';
import { getOutType } from '/@/common/index';
import EviPrint from '/@/views/evidence/unit/component/eviPrint.vue';

export default {
	name: 'BorrowEvidenceList',
	components: { EviPrint},
	props: {
		outType: String,
		showOperation: Boolean,
		caseId: Number,
		selectionEvidences: Array,
		formInline:Object,
		location:String,
	 	},
	setup(props: any) {
		const eviPrintRef = ref();

		const state = reactive({
			showOperation: props.showOperation,
			outTypeTitle: getOutType(props.outType),
			outType: props.outType,
			formInline:props.formInline,
			location:props.location,
			tableData: [],
			options: { tqrs: [], tqdws: [] },
		});
		function onEditEvidenceInfo(row: any) {
			const index = state.tableData.findIndex((x: any) => x.id == row.id);
			state.tableData.splice(index, 1);
		}
		function init() {
			if(props.caseId){
				const _status = state.outType == 6 ? 2 : 1;
				GetCaseBorrowEvdences({
					caseid: props.caseId,
					status: _status,
				}).then((res: any) => {
					if (res.success) {
						state.tableData = res.data;
					}
				});
			}
			else if (props.selectionEvidences?.length > 0) {
				state.tableData = props.selectionEvidences;
			} 
		}

		const onPrintEviInfo = (obj) => {
			var arr=[];
			if(obj){
				obj.location=state.location;
		  	    arr.push(obj);
			}
			debugger

			eviPrintRef.value.openDialog({
				list: arr,
				title: state.formInline.hostUserOrganName,
				caseName: state.formInline.caseName,
				caseNo: state.formInline.caseNo,
				inspectionNo: state.formInline.inspectionNo,
			});
		};

		init();
		return {
			dateFormat,
			onEditEvidenceInfo,
			init,
			onPrintEviInfo,
			eviPrintRef,
			...toRefs(state),
		};
	},
};
</script>
